<template>
    <div class="wy-main business-car-manage">
         <!--标题-->
       <a-row class="wy-main-title">
           <a-col :span="24">
               <p class="title-p">
                   <a-divider class="title-vertical"  type="vertical" />
					<span class="title-span" >管理我的绿色食品采购</span>
					<a-divider class="title-divider"  />
               </p>
           </a-col>
       </a-row>
        <!--搜素框-->
       <div>
          <span><b>农产品类型：</b></span>
          <a-select  :disabled='disabled' v-model="type" style="width: 180px;" placeholder="请选择农产品类型">
          <a-select-option value="">全部</a-select-option>
					<a-select-option v-for="(itme,index) in agriList" :key="index" :value="itme.dictKey">
						{{itme.dictValue}}
					</a-select-option>
		  </a-select>
          <span><b>产地：</b></span>
          <a-input style="width:180px" :disabled='disabled' @click="departureShowMap" v-model="producePlace" placeholder='请选择农产品产地' ref="userNameInput">
			<a-icon type="environment" slot="suffix" style="color: #15837A;" />
		  </a-input>
          
          <!-- <span><b>审核状态：</b></span>
          <a-select defaultValue="全部" style="width:120px">
              <a-select-option value="审核中">审核中</a-select-option>
              <a-select-option value="审核通过">审核通过</a-select-option>
              <a-select-option value="审核未通过">审核未通过</a-select-option>
          </a-select> -->
          
            <span><b>关键字：</b></span>
           <a-input style="width: 120px;" maxLength="50"  v-model="subject" placeholder="请输入关键字"></a-input>
           <a-button type="primary" style="margin-left: 10px;" @click="getAgrSource()">点击查询</a-button>
		   <a-button style="margin-left: 10px;" @click="reset">重置信息</a-button>
			<router-link to="/business/greenpurchasing/publishPurchase">
				<a-button type="primary" style="float: right;">新增产品</a-button>
			</router-link>
            <!--地图Svg显示位置-->
		<map-svg ref="mapSvgDialog" @change="mapSvgCall" @distance="distanceCall"></map-svg>
       </div>
        <div class="route_choice manage_car">
           <a-table :columns="columns" :dataSource="agrdata"  :rowKey="record => record.agricultureSupplyId"  :pagination="pagination" :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys,onChange: onSelectChange}">
               
              <span slot="createTime" slot-scope="text, record">
                <span v-if="!!record.createTime">{{record.createTime.split(" ")[0]}}</span>
              </span>
                 <span slot="approvalStatus" slot-scope="text, record">
                <span class="wei_warning" v-if="record.approvalStatus==106">待审核</span>
                <span class="wei_primary" v-if="record.approvalStatus==107">审核通过</span>
                <span class="wei_danger" v-if="record.approvalStatus==108">审核失败</span>
              </span>
              <!--操作-->
              <span slot="action" slot-scope="text, record">
    			      <a href="javascript:;" @click="seeInfo(record)">查看</a>
    			      <a-divider type="vertical" />
    			      <a href="javascript:;" @click="edit(record)"> 修改</a>
    			      <a-divider type="vertical" />
    			      <a href="javascript:;" @click="delAgrSource(record)" > 删除</a>
    			    </span>
           </a-table>
       </div>
       <div style="margin-top: -50px">
           <a-button @click="delcars()">删除所选</a-button>
       </div>
       <a-modal :title="types == 'edit' ? '编辑' : '查看'" :visible="visible" @cancel="handleCancel" width="900px" :maskClosable='false' :footer="null">
         <city-add v-if="visible" 
			:isSee='isSee' :datail='datail' @cancel="handleCancel" :types='types'></city-add>
       </a-modal>
    </div>
</template>

<script>
import MapSvg from '@/components/dialog/MapSvg'
import { mapState } from 'vuex'
import cityAdd from "./components/CityAdd";
const columns = [{
    title: '农产品采购主题',
    width: 100,
    dataIndex: 'subject',
    key: 'subject' ,
},{
    title: '农产品类型',
    width: 100,
    dataIndex: 'typeValue',
    key: 'typeValue' ,

},{
    title: '农产品名称',
    width: 100,
    dataIndex: 'name',
    key: 'name' ,
},{
    title: '产地',
    width: 100,
    dataIndex: 'producePlace',
    key: 'producePlace' ,
},{
    title: '采购价格',
    width: 100,
    dataIndex: 'price',
    key: 'price' ,

},{
    title: '审核状态',
    width: 100,
    dataIndex: 'approvalStatusValue',
    key: 'approvalStatusValue' ,
     scopedSlots: {
      customRender: 'approvalStatus'
    },
},{
    title: '发布日期',
	dataIndex: 'createTime',
	width:100,
	key: 'createTime',
    scopedSlots: {
      customRender: 'createTime'
    },
},{
    title: '操作',
	width:170,
	key: '0',
	scopedSlots: {
			customRender: 'action'
		},
}];

export default {
    components: {
         MapSvg,
         cityAdd
        
    },
    data() {
        return {
            disabled:false,
            // 地图存起止数据
            departureData: {},
            agriList:[],
            isSee:true,
            type:'',
            types:'',
            producePlace:'',
            subject:'',
            columns,
            agrdata:[],
            loading: false,
            visible:false,
            datail:{},
            pagination: {
      				pageSizeOptions: ['10', '20', '30', '40', '100'],
      				defaultCurrent: 1,
      				defaultPageSize: 10,
      				total:0,
      				showSizeChanger: true,
  				    showTotal: (total, range) => `共 ${total} 条记录`
              },
            selectedRowKeys: [],
            

        }
    },
    created(){
      this.getType(29)
      this.getAgrSource()
    },
    methods: {
       
        distanceCall(num) {
				// this.form.setFieldsValue({ juliNum: num });
			},
            /* 省市地图代码 start */
			// 省市地图回调
			mapSvgCall(d) {
        console.log(d)
				if(d.name === 'departure') {

						this.producePlace = d.provCityArea
					this.departureData = Object.assign({}, d);
				}

			},
      departureShowMap() {
				this.$refs.mapSvgDialog.mapSvgVisible('departure', 2, '', '', '');
      },
      //查询
      getAgrSource(params={}){
        params.pageSize = this.pagination.defaultPageSize
        params.pageNum = this.pagination.defaultCurrent
       if(this.type){
         params.type = this.type
       }

       if(this.producePlace){
        params.producePlace = this.producePlace
       }
        
        if(this.subject){
          params.subject = this.subject
        }
        
//        this.$get('/info/infoVehicleinfo', params).then((r) => {
        this.$get('/info/greenFoodPurchase', params).then((r) => {
          console.log(r)
          this.agrdata = r.data.data.rows
          this.pagination.total = r.data.data.total
        })
      },
            // 删除多条信息
      delcars(){
         if (!this.selectedRowKeys.length) {
          this.$message.warning('请选择需要删除的记录')
          return
        }
        let that = this
        this.$confirm({
          title: '确定删除所选中的记录?',
          content: '当您点击确定按钮后，这些记录将会被彻底删除',
          centered: true,
          onOk () {
            let logIds = that.selectedRowKeys
            console.log(222)
//            for (let key of that.selectedRowKeys) {
//              logIds.push(that.cardata[key].vehicleinfoId)
//            }
          that.$delete('/info/greenFoodPurchase/' + logIds.join(',')).then(() => {
              that.$message.success('删除成功')
              that.selectedRowKeys = []
              that.getAgrSource()
            })
          },
          onCancel () {
            this.visible = false
            that.selectedRowKeys = []
            this.getAgrSource()
          }
        })
      },
      // 删除单条信息
      delAgrSource(data){
        console.log(data)
        let that = this
        this.$confirm({
          title: '确定删除所选中的记录?',
          content: '当您点击确定按钮后，这些记录将会被彻底删除',
          centered: true,
          onOk () {
            let logIds = []
            logIds.push(data.greenFoodPurchaseId)
            that.$delete('/info/greenFoodPurchase/' + logIds.join(',')).then(() => {
              that.$message.success('删除成功')
              that.selectedRowKeys = []
              that.getAgrSource()
            })
          },
          onCancel () {
            that.selectedRowKeys = []
          }
        })
      },
        //关闭弹框
        handleCancel() {
            this.visible = false
            this.getAgrSource()
        },
        //重置
        reset(){
          this.type = ''
          this.producePlace = '' 
          this.subject = ''
          this.getAgrSource()

        },
        //查看
        seeInfo(data){
            this.types = 'add'
            this.visible = true
            this.isSee = true
            this.datail = data

        },
        //修改
        edit(data){
            this.types ='edit'
            this.visible = true
            this.isSee = false
            this.datail = data

        },
     // 获取字典类型
      getType(type){
        this.$get('/info/commonDict', {
          dictType: type
        }).then((r) => {
          if(type == 3){
            console.log(r)
          }
          switch(type){
            case 29: this.agriList = r.data.data.rows; break;
          }
        })
      },
        //全选事件
        onSelectChange (selectedRowKeys) {
		      console.log('selectedRowKeys changed: ', selectedRowKeys);
		      this.selectedRowKeys = selectedRowKeys
		},
          // 表格排序 分页 筛选事件
      handleTableChange (pagination, filters, sorter) {
         this.pagination.defaultPageSize = pagination.pageSize
         this.pagination.defaultCurrent  = pagination.current
         this.getAgrSource()
      },
    }
}

</script>
<style lang="less" scoped>
	.business-car-manage {
		.route_choice {
			margin-top: 20px;
		}
	}
</style>
